import {
  uploadToQiniu
} from "../utils/uploadToQiniu"
Page({

  data: {
    id: '',
    info: null,
    fw: 5,
    zy: 5,
    jz: 5,
    remark: '',
    img: [],
  },


  onLoad(options) {
    this.setData({
      id: options.id
    })
    this.user_order_vehicle_detail()
  },

  user_order_vehicle_detail() {
    getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/user_order_vehicle_detail?id=' + this.data.id).then(res => {
      let data = res.data.data
      this.setData({
        info: data
      })
    })
  },

  bottomTap() {
    const image_icker = this.selectComponent('#image_picker');
    let img_arr = image_icker.linGetValue()
    let num = 0;
    let img = []
    if (img_arr.length == 0) {
      this.vehicle_evaluate()
    } else {
      img_arr.forEach((v, i) => {
        uploadToQiniu(v).then((res) => {
          img.push(res)
          num = num + 1
          if (num == img_arr.length) {
            this.setData({
              img
            })
            this.vehicle_evaluate()
          }
        })
      })
    }
  },

  vehicle_evaluate() {
    getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/vehicle_evaluate', {
      id: this.data.id,
      fw: this.data.fw,
      zy: this.data.zy,
      jz: this.data.jz,
      remark: this.data.remark,
      img: this.data.img.join(',')
    }).then(res => {
      getApp().showModal(res.data.msg).then(() => {
        if (res.data.code == 1) {
          let pages = getCurrentPages();
          let prevPage = pages[pages.length - 2];
          prevPage.setData({
            back: true
          });
          wx.navigateBack({
            delta: 1
          });
        }
      })
    })
  },

  change_remark(e){
    this.setData({
      remark:e.detail.value
    })
  },

})